package com.example.lzy.viewpagerandfragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;


/**
 * Created by Administrator on 2016/7/13.
 */
public abstract class BaseFragment extends Fragment implements View.OnClickListener{

    private FrameLayout progressLayout;
    protected ViewGroup rootView;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        rootView = (ViewGroup)inflater.inflate(getResourceLayout(), null);
        initView(rootView, savedInstanceState);
        initData();
        return rootView;
    }

    protected abstract int getResourceLayout();

    protected abstract void initView(View rootView, Bundle savedInstanceState);

    protected void initData(){}

    @Override
    public void onClick(View v) {

    }

    public void startActivity(Class<? extends Activity> cls, Intent intent){
        intent.setClassName(getContext(), cls.getName());
        startActivity(intent);
    }

    public void startActivity(Class<? extends Activity> cls){
        startActivity(new Intent(getContext(), cls));
    }



    public void hideLoadingLayout(){
        if(progressLayout!=null && progressLayout.getVisibility()== View.VISIBLE){
            progressLayout.setVisibility(View.GONE);
        }
    }

    protected static Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            handleMessage(msg);
            super.handleMessage(msg);
        }
    };

    protected void handleMessage(Message msg){

    }

    public void setListScroll(int y){

    }



    public void onRetry(){

    }

}
